package com.bs.bsacexj.service.impl;

import com.alibaba.fastjson2.JSON;
import com.bs.bsacexj.domain.AccessControlDeviceInfoVO;
import com.bs.bsacexj.domain.PersonInfoVO;
import com.bs.bsacexj.service.IUploadBaseDataService;
import okhttp3.*;
import org.springframework.stereotype.Service;

import java.io.IOException;
import java.util.List;
@Service
public class UploadBaseDataServices implements IUploadBaseDataService {
    @Override
    public boolean uploadACDeviceInfo(List<AccessControlDeviceInfoVO> list) {
        OkHttpClient client = new OkHttpClient();
        String url = "https://aqdlbz-sit.bosafe.com//prod-api/business/accessControlApi/doorResources";
        MediaType mediaType = MediaType.get("application/json; charset=utf-8");
        RequestBody requestBody = RequestBody.create(mediaType, JSON.toJSONString(list));
        Request request = new Request.Builder()
                .url(url)
                .post(requestBody)
                .build();
        Boolean result=true;
        try (
                Response response = client.newCall(request).execute()) {
            ResponseBody body = response.body();
        } catch (IOException e) {
            result=false;
            throw new RuntimeException(e);
        }
        return result;
    }

    @Override
    public boolean uploadUserInfo(List<PersonInfoVO> personInfoVOList) {
        OkHttpClient client = new OkHttpClient();
        String url = "https://aqdlbz-sit.bosafe.com/prod-api/business/accessControlApi/personInfoList";
        MediaType mediaType = MediaType.get("application/json; charset=utf-8");
        RequestBody requestBody = RequestBody.create(mediaType, JSON.toJSONString(personInfoVOList));
        Request request = new Request.Builder()
                .url(url)
                .post(requestBody)
                .build();
        try (
                Response response = client.newCall(request).execute()) {
            ResponseBody body = response.body();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        return true;
    }
}
